export const state = () => ({
    key : '',
    model: '',
})

export const mutations = {
    setKey(state, key){
        state.key = key
    },
    setModel(state, model){
        state.model = model
    }
}

export const actions = {
    getWordList({}, name, keywords) {
        return this.$api.search.getWordList(name,keywords).then((res) => {
            console.log(res.data.status)
            if(res.data.code === 200) {
                return Promise.resolve(res.data.data)
            }
            else {
                return Promise.reject(res.data.msg)
            }
        }, (error) => {
            return Promise.reject(error)
        }).catch((error) => {
            return Promise.reject(error)
        })
    },
    think({},{keywords, word, type}){
        return this.$api.search.think(keywords,word,type).then((res)=>{
            if(res.data.code === 200) {
                return Promise.resolve(res.data.data)
            }
            else {
                return Promise.reject(res.data.msg)
            }
        }, (error) => {
            return Promise.reject(error)
        }).catch((error) => {
            return Promise.reject(error)
        })
    },
    postRank({},{model, score}){
      return this.$api.search.postRank(model, score).then((res)=>{
        if(res.data.code === 200) {
            return Promise.resolve(res.data.data)
        }
        else {
            return Promise.reject(res.data.msg)
        }
      },(error)=>{
          return Promise.reject(error)
      }).catch((error)=>{
          return Promise.reject(error)
      })  
    },
    setKey({commit}, key){
        commit('setKey',key)
    },
    delKey({commit}){
        commit('setKey','')
    },
    setModel({commit}, model){
        commit('setModel',model)
    },
    delModel({commit}){
        commit('setModel','')
    },
    deploy({},{name, category}){
        return this.$api.search.deploy(name, category).then((res)=>{
            if(res.data.code === 200) {
                return Promise.resolve(res.data.data)
            }
            else {
                return Promise.reject(res.data.msg)
            }
          },(error)=>{
              return Promise.reject(error)
          }).catch((error)=>{
              return Promise.reject(error)
          }) 
    },
    getModels(){
        return this.$api.search.getModels().then((res)=>{
            if(res.data.code === 200) {
                return Promise.resolve(res.data.data)
            }
            else {
                return Promise.reject(res.data.msg)
            }
          },(error)=>{
              return Promise.reject(error)
          }).catch((error)=>{
              return Promise.reject(error)
          }) 
    },
    getRank({},name){
        return this.$api.search.getRank(name).then((res)=>{
            if(res.data.code === 200) {
                return Promise.resolve(res.data.data)
            }
            else {
                return Promise.reject(res.data.msg)
            }
          },(error)=>{
              return Promise.reject(error)
          }).catch((error)=>{
              return Promise.reject(error)
          }) 
    }
}